using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.Xpo;
using TaiLieu;
namespace TaiLieu
{
    public class MenuDB : Base
    {
        /// <summary>
        /// public static XPCollection<ContentManagement> GetAll()
        /// </summary>
        /// <returns>XPCollection<ContentManagement></returns>
        public static XPCollection<Menu> GetAll(bool admin, string domain)
        {
            XPCollection<Menu> _xp = new XPCollection<Menu>(KetNoiCSDL.session);
            string filter = ColumMenu._web + "='" +domain+ "'";
            if (admin == false)
            {
                filter += " and Active=true";
                _xp.Filter = DevExpress.Data.Filtering.CriteriaOperator.Parse(filter);
                _xp.Sorting = SetupSort(ColumMenu._Priority, true);
            }
            else
            {
                _xp.Filter = DevExpress.Data.Filtering.CriteriaOperator.Parse(filter); _xp.Sorting = SetupSort(ColumMenu._Active, false);
            }
            return _xp;
        }
        public static ICollection<Menu> GetAll()
        {
            return KetNoiCSDL.session.GetObjectsFromQuery<TaiLieu.Menu>("SELECT * FROM [Menu] order by System");
        }
        /// <summary>
        /// public static ContentManagement GetObjectByid(int id)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Menu GetObjectByid(int id, bool admin, string domain)
        {
           return KetNoiCSDL.session.GetObjectByKey<Menu>(id);
        }
        public static Menu GetObjectByid(int id)
        {
            return KetNoiCSDL.session.GetObjectByKey<Menu>(id);
        }
        public static ICollection<Menu> GetObjectByQuery(bool admin, string query)
        {
            if(admin==true)
            return KetNoiCSDL.session.GetObjectsFromQuery<Menu>("select * from Menu where  query like '%" + query + "'");
            return KetNoiCSDL.session.GetObjectsFromQuery<Menu>("select * from Menu where active=1 and  query like '%" + query + "'");
        }
        public static ICollection<Menu> GetMenuFrontend()
        {
            return KetNoiCSDL.session.GetObjectsFromQuery<TaiLieu.Menu>("SELECT * FROM [Menu] where active=1 and query!='/trang-chu' order by priority");
        }
    }
}
